package 剑指offer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

public class _32从上到下打印二叉树 {
	public static void main(String[] args) {
    	Queue<Integer> queue=new LinkedList<Integer>();
    	queue.add(1);
    	queue.add(2);
    	queue.add(3);
    	System.out.println(queue.poll());
    	System.out.println(queue.poll());
    	System.out.println(queue.poll());
	}
    public int[] levelOrder(TreeNode root) {
    	if(root==null) return new int [0];
    	Queue<TreeNode> queue=new LinkedList<TreeNode>();
    	ArrayList<Integer> list=new ArrayList<Integer>();
    	queue.add(root);
    	while(!queue.isEmpty()) {
    		TreeNode node=queue.poll();
    		list.add(node.val);
    		if(node.left!=null) queue.add(node.left);
    		if(node.right!=null) queue.add(node.right);
    		
    	}
    	int []res=new int[list.size()];
    	for (int i = 0; i < list.size(); i++) {
			res[i]=list.get(i);
		}
		return res;

    }
    
}
